const fs = require('fs');
const router = require('koa-router')();
const fileUploader = require('../exts/FileUploadHelper');

router.prefix('/api/file', '文件上传下载服务');

router.post('/upload', async (ctx, next) => {
    let rs = ctx.getResponse();
    let file = fileUploader.upload(ctx);

    rs.data = file;

    await (ctx.body = rs);
}, {
    desc: '文件上传', multipart: [
        { type: 'boolean', name: 'keepFileName', desc: '保持文件名' },
        { type: 'file', name: 'files', desc: '上传文件' }
    ]
});

module.exports = router;